package com.example.controller;

import com.example.common.Result;
import com.example.entity.Book;
import com.example.entity.Hotel;
import com.example.entity.Params;
import com.example.service.HotelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: PengFei.He
 * @Date: 2024/11/6 19:59
 * @Function:
 */

@RestController
@RequestMapping("/hotel")
public class HotelController {

    private static final Logger log = LoggerFactory.getLogger(HotelController.class);

    @Autowired
    private HotelService hotelService;

    @GetMapping("/search")
    public Result findBySearch(Params params){
        //1.开启分页
        PageHelper.startPage(params.getPageNum(),params.getPageSize());
        //2.查询信息
        List<Hotel> list = hotelService.findBySearch(params);
        //3.封装对象
        PageInfo<Hotel> info = PageInfo.of(list);
        return Result.success(info);
    }


    @PostMapping
    public Result save(@RequestBody Hotel hotel){
        hotelService.add(hotel);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable Integer id){
        hotelService.removeById(id);
        return Result.success();
    }
}
